package com.towncoder.controller.admin;

import com.towncoder.entity.Vehicle;
import com.towncoder.service.VehicleService ;


import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


    /**
     * 车辆表(Vehicle)表控制层
     *
     * @author makejava
     * @since 2024-08-22 21:54:10
     */
    @RestController
    @RequestMapping("vehicle")
    public class VehicleController {
        /**
         * 服务对象
         */
        @Resource
        private VehicleService vehicleService;


        /**
         * 通过主键查询单条数据
         *
         * @param id 主键
         * @return 单条数据
         */
        @GetMapping("{id}")
        public ResponseEntity<Vehicle> queryById(@PathVariable("id") Long id) {
            return ResponseEntity.ok(this.vehicleService.queryById(id));
        }

        /**
         * 新增数据
         *
         * @param vehicle 实体
         * @return 新增结果
         */
        @PostMapping
        public ResponseEntity<Vehicle> add(Vehicle vehicle) {
            return ResponseEntity.ok(this.vehicleService.insert(vehicle));
        }

        /**
         * 编辑数据
         *
         * @param vehicle 实体
         * @return 编辑结果
         */
        @PutMapping
        public ResponseEntity<Vehicle> edit(Vehicle vehicle) {
            return ResponseEntity.ok(this.vehicleService.update(vehicle));
        }

        /**
         * 删除数据
         *
         * @param id 主键
         * @return 删除是否成功
         */
        @DeleteMapping
        public ResponseEntity<Boolean> deleteById(Long id) {
            return ResponseEntity.ok(this.vehicleService.deleteById(id));
        }

    }



